<?php
namespace app\index\controller;
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods:POST,GET");

use app\common\controller\HomeBase;

use think\Db;

class Storeminor extends HomeBase
{
	protected function _initialize(){
		parent::_initialize();
	}


	/**
	*车商城全部驱动    
	**/
	public function drive()
	{
		$list = Db('store_classify')->where('pid',4)->select();
		$this->doif($list);
	}

	/**
	*车商城二级页面  (点击品牌进去,或者点击更多车型进去) 
	*@param   brand         品牌的id
	*@param   low           最低价
	*@param   high          最高价
	*@param   type          类型
	*@param   drive         驱动		         
	**/
	public function carList()
	{
		//获取参数
		$brand = (isset($_GET['brand']) ? $_GET['brand']:'');
		$low = (isset($_GET['low']) ? $_GET['low']:0);
		$high =(isset($_GET['high']) ? $_GET['high']:10000);
		$type =(isset($_GET['type']) ? $_GET['type']:'');
		$drive =(isset($_GET['drive']) ? $_GET['drive']:'');

		//查询
		$map['status'] = 1; 
		if($brand){
            $map['brand'] = $brand;
        }
		if($type){
            $map['type'] = $type;
        }
        if($drive){
            $map['drive'] = $drive;
        }
		$CarList1 =  Db('store_truck')->where($map)->where('price','>=',$low)->where('price','<',$high)->where('is_top',1)->select();
		$CarList2 =  Db('store_truck')->where($map)->where('price','>=',$low)->where('price','<',$high)->where('is_top',0)->select();
		$CarList = array_merge($CarList1,$CarList2);
		$i = 0;
		for(;$i < count($CarList);$i++){
			$drive = $CarList[$i]['drive'];
			$arr = Db('store_classify')->where('id',$drive)->select();
			$CarList[$i]['drive'] = $arr[0]['name'];

			if (!$CarList[$i]['photo']) {
				$CarList[$i]['photo'] = unserialize($CarList[$i]['photo']);
			}
		}
		$this->doif($CarList);
	}



	/**
	*公共方法:将数组进行判断
	*@param  $arr		  要判断的数组
	**/
	public function doif($arr)
	{
		if($arr){
            $this->apiSuccess($arr);
        }else{
            $this->apiError('没有查到信息');
        }
	}

}